package org.fujay.langchain4jserver.domain.conversation.vo;

import lombok.Value;

import java.io.Serial;
import java.io.Serializable;

/**
 * Token用量值对象
 */
@Value
public class TokenUsage implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    long promptTokens;
    long completionTokens;
    long totalTokens;

    public TokenUsage(long promptTokens, long completionTokens) {
        if (promptTokens < 0 || completionTokens < 0) {
            throw new IllegalArgumentException("token数量必须大于0");
        }
        this.promptTokens = promptTokens;
        this.completionTokens = completionTokens;
        this.totalTokens = promptTokens + completionTokens;
    }

    public static TokenUsage zero() {
        return new TokenUsage(0L, 0L);
    }
}
